﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
namespace MyDay13.Filter
{
    public class MalFIlter : IExceptionFilter
    {
        NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();

        public void OnException(ExceptionContext context)
        {
            Exception ex = context.Exception;
            var errmsg = "错误信息为" + ex.Message;
            context.Result = new JsonResult(new
            {
                stata = false,
                mesg = errmsg
            });
            Logger.Error(errmsg);
            context.ExceptionHandled = true;

            /*//获取本机ip
            var addresslist = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName()).AddressList;
            var ip = addresslist.FirstOrDefault(x => x.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)?.ToString();*/



        }
    }
    public class MalFIlters : IAuthorizationFilter
    {
        public void OnAuthorization(AuthorizationFilterContext context)
        {
            var name = context.HttpContext.User.Identity.Name;
            var path = context.HttpContext.Request.Path;
        }
    }
}
